<?
/*********************************************
 *企业列表(包含企业发的招聘信息)
 * *******************************************/
function smarty_function_qishi_company_list($params, &$smarty)
{
	extract($params);
	global $db;
	$listname = (NULL != $listname) ? $listname : "list"; //默认的循环变量名称
	$row = (NULL != $row) ? $row : 15; //默认显示记录数量
	$start  = (NULL != $start) ? $start : 0; //从第几条开始读取，缺省0
	$companynamelen = (NULL != $companynamelen) ? $companynamelen : 15; //默认公司名称长度
	$jobslen = (NULL != $jobslen) ? $jobslen : 5; //默认职位名称长度
	$jobsrow = (NULL != $jobsrow) ? $jobsrow : 3; //默认显示职位记录数量
	$companydot = (NULL != $companydot) ? $companydot : ''; //公司名称默认截取后填补字符
	$jobsdot = (NULL != $jobsdot) ? $jobsdot : '';
	$trade = (NULL != $trade) ? $trade : ''; //行业
	$settr = (NULL != $settr) ? $settr : "";
	$trade?$wheresql=" AND trade='".intval($trade)."' ":'';//行业
	//是否显紧急招聘
	if ($emergency)
	{
		$where_emergency=" AND emergency='2' ";
	}
	//是否只显示推荐企业
	if ($recommend)
	{
		$where_recommend=" AND recommend='1' ";
	}
	//删选时间段
	if (intval($settr))
	{
		$settr_val=strtotime("-".$settr." day");
		$wheresql.=" AND addtime > ".$settr_val;
	}
	//读取开始位置，和条数限制
	if(!empty($row))
	{
		$offset=$start?$start:0;
		$limit=" LIMIT ".$offset.','.$row;
	}
	//排列字段
	$orderby=ereg('refreshtime|addtime|id',$orderby)?$orderby:"refreshtime";
	//显示顺序
	$displayorder=ereg('asc|desc',$displayorder)?$displayorder:"DESC";
	//sql语句
	$orderbysql=" ORDER BY ".$orderby." ".$displayorder;
	$result = $db->query("SELECT * FROM ".table('company_profile')." WHERE uid IN (select uid from ".table('jobs')." WHERE audit='1' and display='1' ".$where_emergency.") ".$wheresql.$where_recommend.$orderbysql.$limit);
	while($row = $db->fetch_array($result))
	{
//		$row['companyname']=cut_str($row['companyname'],$companynamelen,0,$companydot);
		$row['companyname']=cut_str($row['company_name_cn'],$companynamelen,0,$companydot);
		$row['url']=url_rewrite('company',array('id0'=>$row['id']));
		$row['jobs']=get_company_jobs(0,$jobsrow,"  WHERE uid=".$row['uid']." AND audit='1' and display='1' ".$where_emergency." ",$jobslen,$jobsdot);
		$row_arr[] = $row;
	}
	//
	$smarty->assign($listname, $row_arr);
	unset($row_arr);
}
//获取职位列表
function get_company_jobs($offset,$perpage,$get_sql= '',$jobslen=10,$dot="")
{
	global $db,$timestamp;
	$row_arr = array();
	if(isset($offset)&&!empty($perpage))
	{
		$limit=" LIMIT ".$offset.','.$perpage;
	}
	$result = $db->query("SELECT * FROM ".table('jobs')." ".$get_sql." ORDER BY id DESC ".$limit);
	while($row = $db->fetch_array($result))
	{
		$row['jobs_name']=cut_str($row['jobs_name_cn'],$jobslen,0,$dot);
		$row['jobs_url']=url_rewrite('jobs-show',array('id0'=>$row['id']));
		$row_arr[] = $row;
	}
	return $row_arr;
}
?>